package net.ib.rpc;

import com.google.protobuf.RpcCallback;
import com.google.protobuf.RpcController;

/**
 * m&talk server ConnectionController
 * 
 * @author zagals@infobank.net
 * @version 1.0
 * @since 11/02/24
 * @history
 */
public class ConnectionController implements RpcController {
	private final Connection connection;
	private long timeoutMillis = -1;

	public ConnectionController(Connection connection) {
		this.connection = connection;
	}

	public Connection getConnection() {
		return connection;
	}

	@Override
	public void reset() {
		// Client Side Only
		System.out.println("ConnectionController : reset()");
	}

	@Override
	public void startCancel() {
		// Client Side
		System.out.println("ConnectionController : startCancel()");
	}

	@Override
	public boolean failed() {
		// Client Side Only
		// 호출이 끝나기 전에 불리면 안된다.
		System.out.println("ConnectionController : failed()");
		return false;
	}

	@Override
	public String errorText() {
		// Client Side
		// failed() 가 true 이면 사람이 읽을 수 있는 문자로 에러를 묘사한다.
		System.out.println("ConnectionController : errorText()");
		return null;
	}

	@Override
	public void setFailed(String arg0) {
		// Server Side
		// failed data set
		System.out.println("ConnectionController : setFailed() arg0 : " + arg0);
	}

	@Override
	public boolean isCanceled() {
		// Server Side Only
		// RPC 클라이언트가 끊어지면 true
		System.out.println("ConnectionController : isCanceled()");
		return false;
	}

	@Override
	public void notifyOnCancel(RpcCallback<Object> arg0) {
		// Server Side
		System.out.println("ConnectionController : notifyOnCancel() arg0 : "
				+ arg0);
	}

	public ConnectionController setTimeoutMillis(long timeoutMillis) {
		this.timeoutMillis = timeoutMillis;
		return this;
	}

	public long getTimeoutMillis() {
		return this.timeoutMillis;
	}

}
